package com.yumijinfu.activity;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.yumijinfu.R;
import com.yumijinfu.base.BaseActivity;
import com.yumijinfu.http.HttpCallBack;
import com.yumijinfu.http.HttpUtils;
import com.yumijinfu.mian.Config;
import com.yumijinfu.view.TitleBar;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 鱼米巾服介绍
 */
public class YuMiIntroduceActivity extends BaseActivity {

    @Bind(R.id.titlebar)
    TitleBar titlebar;
    @Bind(R.id.pb_loading)
    ProgressBar pb_progress;
    @Bind(R.id.mWebView)
    WebView vWVContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_yu_mi_introduce);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {

        titlebar.setTitleBar(R.drawable.back_selector, "关于鱼米", 0);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void setData() {

        vWVContent.setWebViewClient(new WebViewClient());
        vWVContent.getSettings().setJavaScriptEnabled(true);
        vWVContent.getSettings().setBuiltInZoomControls(true); //显示放大缩小 controler
        vWVContent.getSettings().setSupportZoom(true); //可以缩放
        vWVContent.getSettings().setUseWideViewPort(true);
        vWVContent.getSettings().setLoadWithOverviewMode(true);
        vWVContent.setInitialScale(100);

        vWVContent.setWebChromeClient(new WebChromeClient(){


            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                pb_progress.setProgress(newProgress);
                if(newProgress==100){
                    pb_progress.setVisibility(View.GONE);
                }
            }

        });

        getIntroductionData();
    }

    private void getIntroductionData() {
        HttpUtils.get(Config.INTRODUCTION, new HttpCallBack(this,"加载中...") {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {

                if(null!=result){
                    String url=result.optString("url");
                    vWVContent.loadUrl(url);
                }
            }

            @Override
            public void onError(String code, String message) {
                Toast.makeText(YuMiIntroduceActivity.this, message, Toast.LENGTH_SHORT).show();

            }
        });
    }


    @OnClick({R.id.titlebar_iv_back})
    @Override
    public void widgetClick(View v) {

        switch (v.getId()) {

            case R.id.titlebar_iv_back:

                finish();

                break;

            default:
        }
    }




}
